import { observable, action } from 'mobx';

import { ListViewPage, SearchAdvanced } from 'weaver-mobile-page';
import { Bubble,Tools,Modal } from 'weaver-mobile'
import * as Api from '../../api/CenterApi';
import { PARAMS } from '../../util';

const getLabel = Tools.getLabel;
const alert = Modal.alert;

export default class CommentMonitorStore {

    @observable viewRight = 0;//页面权限
    @observable commentpage = 'undelete';
    @observable commentvisible = false;
    @observable commentLoading = true;
    @observable commentSearch = new SearchAdvanced.Store({ route: '/center/comment', id: 'commentSearch' }); //评论监控-高级搜索
    @observable commentList = new ListViewPage.Store({ route: '/center/comment', id: 'comment' });  // 评论监控列表
    @observable showCommentCheck = false; //评论监控-批量操作
    @observable commentAdValue = ''; //高级搜索值受控

    @observable commentDeleteLoading = true;
    @observable commentDeleteSearch = new SearchAdvanced.Store({ route: '/center/comment', id: 'commentDeleteSearch' }); //评论监控-高级搜索
    @observable commentDeleteList = new ListViewPage.Store({ route: '/center/comment', id: 'contentDelete' });  // 评论监控列表
		@observable commentDeleteAdValue = ''; //高级搜索值受控
		@observable currentModel = {}; //当前对话框弹窗

    @action setStoreState = (params) => {
        Object.keys(params).forEach(key => {
          this[key] = params[key];
        })
      }

    /*************************************************** 评论监控 ***************************************************/
    @action('评论监控列表请求')
    getCommentList = () => {
    const commentSearchParams = this.commentSearch.form.formParams || {};
    const params = {
            typeid:0,
            datetype:0,
            commentStatus:0,
            ...commentSearchParams,
        }
    Api.getCoworkCommentMonitorList(params).then(res => {
        const dataKey = res.sessionkey;
        this.viewRight = res.viewRight
        if(this.viewRight === 0 ){
          this.commentLoading = false;
        }
        else if (dataKey) {
            this.dataKey = dataKey;
            this.commentList.getData({ dataKey }, ()=> this.commentLoading = false, true);
            this.commentLoading = false;

        }
    })
    }

    @action("评论监控高级搜索")
    getCoworkCommentMonitorShareCondition = (params) => {
    params = {  
        ...params,
        ...PARAMS,
    }
    if(params.commentType === "delete"){
        this.commentDeleteSearch.getData({
            url: '/api/cowork/commentMonitor/getCoworkCommentMonitorShareCondition',
            method: 'GET',
            params:params,
        })
    }else{
        this.commentSearch.getData({
            url: '/api/cowork/commentMonitor/getCoworkCommentMonitorShareCondition',
            method: 'GET',
            params:params,
        })
    }
  
    }

    @action("评论监控删除")
    batchCommentMonitorDel = (params) => {
    params = {
        ...params,
    }
    this.currentModel = alert(getLabel(388758, '确认要删除吗？'),'', [
        { text: getLabel(31129, '取消') },
        {
        text: getLabel(33703, '确认'),
        onPress: () => {
            Api.batchCommentMonitorDel(params).then(res => {
                const status = res.status;
                if (status === "1") {
                this.getCommentList();
                this.doCommentCancel();
                Bubble.success(getLabel(30700, '操作成功')+'!', 1);
                }
            })
        }
        },
    ])
    }

    // 评论监控 -- 高级搜索内外name统一
    @action updateCommentAdvance = (value) => {
    this.commentAdValue = value;
    this.commentSearch.form.updateField('remark', value);
    }

    // 评论监控 -- 取消
    @action doCommentCancel = () => {
    this.showCommentCheck = false;
    this.doCommentselectNone();
    }

    // 评论监控 -- 全选
    @action doCommentSelectAll = () => this.commentList.selectAll();

    // 评论监控 -- 取消全选
    @action doCommentselectNone = () => this.commentList.selectNone();

    // 评论监控 -- 高级搜素 -- 重置
    @action doCommentReset = () => {
    this.commentSearch.form.resetFields();
    this.commentAdValue = '';
    this.getCommentList();
    }

    // 评论监控 -- 组件挂载时处理
    @action doCommentMount = () => {
    this.commentSearch.form.resetFields();
    this.commentAdValue = '';
    }

    /*************************************************** 评论监控已删除 ***************************************************/
    @action('评论监控已删除列表请求')
    getCommentDeleteList = () => {
    const commentDeleteSearchParams = this.commentDeleteSearch.form.formParams || {};
    const params = {
        typeid:0,
        del_datetype:0,
        commentStatus:1,
        ...commentDeleteSearchParams,
    }
    Api.getCoworkCommentMonitorList(params).then(res => {
        const dataKey = res.sessionkey;
        this.viewRight = res.viewRight
        if(this.viewRight === 0 ){
          this.commentLoading = false;
        }
        else if(dataKey) {
            this.dataKey = dataKey;
            this.commentDeleteList.getData({ dataKey }, ()=> this.commentDeleteLoading = false, true);
            this.commentDeleteLoading = false;
           
        }
    })

    }

    // 评论监控 -- 高级搜索内外name统一
    @action updateCommentDeleteAdvance = (value) => {
        this.commentDeleteAdValue = value;
        this.commentDeleteSearch.form.updateField('remark', value);
    
    }
    // 评论监控 -- 高级搜素 -- 重置
    @action doCommentDeleteReset = () => {
        this.commentDeleteSearch.form.resetFields();
        this.commentDeleteAdValue = '';
        this.getCommentDeleteList();
    }
    
        // 评论监控 -- 组件挂载时处理
    @action doCommentDeleteMount = () => {
        this.commentDeleteSearch.form.resetFields();
        this.commentDeleteAdValue = '';
        this.commentpage = 'undelete';
    }

	//关闭所有弹窗
	@action closeAllModel = () => {
		this.currentModel && typeof this.currentModel.close === 'function' && this.currentModel.close();
	}
}